home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / mail / mh / contrib / 9210 / bipp.shar / bipp next >
Text File  |  1992-10-22  |  1KB  |  45 lines

  1. #! /bin/sh
  2. # $Header: /home/jerry/.bin/RCS/bipp,v 1.4 92/10/23 10:41:28 jerry Exp $
  3. ###    bipp - backquote interpolating prompter preprocessor :-)
  4. ###    Usage (in MH profile):  comp: -editor bipp   (etc., or Editor: bipp)
  5. ## Reads a "components" file, runs commands between backquotes (in header only!)
  6. ## starts "prompter" on the edited file.  Sort of a hack, but it's a good start.
  7. #
  8. # Placed in the public domain by Jerry Peek, jerry@ora.com, 23 October 1992.
  9. # Use this at your own risk, inspect and fix before you use it, etc.
  10. # If this doesn't work the way you expect it to, that's your responsibility!
  11.  
  12. stat=1  # DEFAULT EXIT STATUS (RESET TO 0 FOR NORMAL EXIT)
  13. temp=/tmp/EDIT$$
  14. trap 'rm -f $temp; exit $stat' 0 1 2 15
  15.  
  16. nawk '
  17. BEGIN {
  18.     inheader = 1
  19. }
  20. inheader == 1 {
  21.     if ($0 ~ /^-*$/) {
  22.     # END OF HEADER
  23.     inheader = 0
  24.     }
  25.     else if (match($0, /`.*`/)) {
  26.     # GET STRING, WITHOUT THE BACKQUOTES:
  27.     torun = substr($0, RSTART + 1, RLENGTH - 2)
  28.     # QUICK-AND-DIRTY: GET ONE LINE OF OUTPUT FROM torun:
  29.     torun | getline tosub
  30.     if (sub(/`.*`/, tosub) != 1) {
  31.         printf "**** ERROR RUNNING `%s` ***\n", torun
  32.         next
  33.     }
  34.     }
  35. }
  36. {
  37.     print
  38. }' $1 > $temp
  39. # REPLACE DRAFT WITH EDITED VERSION; START prompter IF cp WORKED:
  40. if cp $temp $1
  41. then
  42.     prompter $1
  43.     stat=$?       # EXIT WITH STATUS FROM prompter
  44. fi
  45.